#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(void)
{    Mat gray;
     Mat image;//创建摄像头
     CascadeClassifier  classifier("/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml");
     VideoCapture cap;
     cap.open(0);
     if(!(cap.isOpened()))
     {
       cout << "open error" << endl;

     }
     cout << "start rrabbing" << endl;
     while(1)
     {
     cap.read(image);
     //将3通道的彩色图像转成当通道的灰度图像
     cvtColor(image,gray,CV_BGR2GRAY);
   
     equalizeHist(gray,gray);

     vector<Rect>faces;
     //检测人脸
     classifier.detectMultiScale(gray,faces);
     if(faces.size())  //判断是否检测到人脸
     {
         //将检测到的人脸用举行款款起来
	 rectangle(image,faces[0],CV_RGB(255,0,0));
     }
     
     imshow("camera",image);
     //waitKey(0);
     //waitKey(40);
     // cout << waitKey(40)<< endl //返回之255
     if(waitKey(40) !=255)
     {
       break;
     }
     } 
     return 0;
}
